Namespace persistent

    Public Class Bulk_Service_Requests_Giris
        Public Shared Function GetCompanyValues(ByVal p_Custcode_Girilen, ByVal p_CorpSeviye_Girilen, ByRef p_custcode_donecek, ByRef p_custid_donecek, ByRef p_sme_la_flag_donecek, ByRef l_sirket_adi_donecek) As String
            Dim l_dt As DataTable
            Dim l_SME_LA As String
            Dim sql As String
            Dim l_HighestCustcode As String
            Dim l_HighestCustomerid As String

            sql = "select  toplevel.CUSTCODE, toplevel.CUSTOMER_ID, nvl(decode(substr(curlevel.custcode, 1, 1), '1', (select tmtype from tarifftype t1 where t1.tmcode = curlevel.tmcode), 'L'), 'O') SME_LA_FLAG " + vbCrLf
            sql = sql + "	from CUSTOMER_ALL curlevel, CUSTOMER_ALL toplevel  " + vbCrLf
            sql = sql + "	where curlevel.CUSTCODE = '[TAG1]' " + vbCrLf
            sql = sql + "		and decode(decode(nvl(curlevel.CSLEVEL,0), [TAG2], curlevel.CUSTOMER_ID, nvl(curlevel.CUSTOMER_ID_HIGH, 0)), " + vbCrLf
            sql = sql + "				0, (select CUSTOMER_ID from CONTRACT_ALL where CO_ID = (select max(a.CO_ID) from CONTRACT_ALL a, CURR_CO_STATUS b where a.CUSTOMER_ID = curlevel.CUSTOMER_ID and a.CO_ID = b.CO_ID and b.CH_STATUS <> 'd')), " + vbCrLf
            sql = sql + "				sysadm.fn_la_getcustidhigh([TAG2], curlevel.CUSTOMER_ID)) = toplevel.CUSTOMER_ID " + vbCrLf
            sql = sql.Replace("[TAG1]", p_Custcode_Girilen)
            sql = sql.Replace("[TAG2]", p_CorpSeviye_Girilen)
            Dim l_dt2 As DataTable
            l_dt2 = myDBConn.myORATable(sql)
            l_HighestCustcode = CStr(l_dt2.Rows(0).Item("CUSTCODE"))
            l_SME_LA = CStr(l_dt2.Rows(0).Item("SME_LA_FLAG"))
            l_HighestCustomerid = CStr(l_dt2.Rows(0).Item("CUSTOMER_ID"))

            p_sme_la_flag_donecek = l_SME_LA
            p_custid_donecek = l_HighestCustomerid
            p_custcode_donecek = l_HighestCustcode

            'sql = "select  CCNAME from CCONTACT_ALL where CUSTOMER_ID = (select CUSTOMER_ID from CUSTOMER_ALL where CUSTCODE = '[TAG1]') and CCBILLDETAILS = 'X' "
            sql = "SELECT NVL(CCNAME, CCFNAME || ' ' || CCLNAME) CCNAME " & _
            vbNewLine & "FROM CCONTACT_ALL CCOA, CUSTOMER_ALL CUA, BILLING_ACCOUNT BA " & _
            vbNewLine & "WHERE CCOA.CUSTOMER_ID = CUA.CUSTOMER_ID " & _
            vbNewLine & "AND BA.CUSTOMER_ID = CCOA.CUSTOMER_ID " & _
            vbNewLine & "AND BA.PRIMARY_FLAG = 'X' " & _
            vbNewLine & "AND (CCOA.CCSEQ = BA.CONTACT_SEQNO OR BA.CONTACT_SEQNO IS NULL) " & _
            vbNewLine & "AND CUA.CUSTCODE = '[TAG1]'"

            sql = sql.Replace("[TAG1]", l_HighestCustcode)
            l_sirket_adi_donecek = myDBConn.ORAScalar(sql)
            If IsDBNull(l_sirket_adi_donecek) Then l_sirket_adi_donecek = String.Empty
            Return "OK"
        End Function

    End Class

End Namespace
